package com.fr.chart.core.glyph;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.core.util.vt.VT4FR;
import com.fr.base.core.util.vt.VT4FR.FUNC;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.Meter;
import com.fr.chart.plot.MeterStyle;
import java.awt.Graphics;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;

public class MeterPlotGlyph extends PlotGlyph
{
  private static final long serialVersionUID = -7720249461263542792L;
  public static final double GAP = 10.0D;
  public static final String XML_TAG = "MeterPlotGlyph";
  private MeterStyle meterStyle;

  public void layoutAxisGlyph()
  {
  }

  public void layoutDataSeriesGlyph()
  {
    if (!(VT4FR.ADVANCED_CHART.support()))
      return;
    Rectangle2D localRectangle2D = getBounds();
    int i = getSeriesSize();
    int j = getCategoryCount();
    double d1 = (localRectangle2D.getHeight() - (i + 1) * 10.0D) / i;
    double d2 = (localRectangle2D.getWidth() - (j + 1) * 10.0D) / j;
    for (int k = 0; k < i; ++k)
    {
      DataSeries localDataSeries = getSeries(k);
      for (int l = 0; l < j; ++l)
      {
        DataPoint localDataPoint = localDataSeries.getDataPoint(l);
        if (localDataPoint.isValueIsNull())
          break label271:
        String str = localDataPoint.getCategoryName();
        Dimension2D localDimension2D = TextGlyph.calculateTextDimension(str, getMeterStyle().getTitleTextAttr());
        TextGlyph localTextGlyph = new TextGlyph(str, getMeterStyle().getTitleTextAttr());
        localTextGlyph.setBounds(new Rectangle2D.Double((d2 - localDimension2D.getWidth()) * 0.5D, -localDimension2D.getHeight(), localDimension2D.getWidth(), localDimension2D.getHeight()));
        Meter localMeter = new Meter(localTextGlyph, localDataPoint.getValue(), getMeterStyle());
        localDataPoint.setDrawImpl(localMeter);
        localMeter.setBounds(new Rectangle2D.Double(l * d2 + (l + 1) * 10.0D, k * d1 + localDimension2D.getHeight(), d2, d1 - localDimension2D.getHeight()));
        dealDataPointLabelBounds(localDataPoint, k);
      }
    }
    label271:
  }

  public void draw(Graphics paramGraphics)
  {
    drawInfo(paramGraphics);
    super.draw(paramGraphics);
  }

  public void setMeterStyle(MeterStyle paramMeterStyle)
  {
    this.meterStyle = paramMeterStyle;
  }

  public MeterStyle getMeterStyle()
  {
    return this.meterStyle;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("MeterPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    if (this.meterStyle != null)
      this.meterStyle.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("MeterStyle"))
        this.meterStyle = ((MeterStyle)paramXMLableReader.readXMLObject(new MeterStyle()));
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof MeterPlotGlyph))
      return false;
    MeterPlotGlyph localMeterPlotGlyph = (MeterPlotGlyph)paramObject;
    if (!(super.equals(localMeterPlotGlyph)))
      return false;
    return (Equals.equals(localMeterPlotGlyph.meterStyle, this.meterStyle));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    MeterPlotGlyph localMeterPlotGlyph = (MeterPlotGlyph)super.clone();
    if (this.meterStyle != null)
      localMeterPlotGlyph.meterStyle = ((MeterStyle)this.meterStyle.clone());
    return localMeterPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if (this.meterStyle != null)
      localJSONObject.put("meterStyle", this.meterStyle.toJSONObject());
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "MeterPlotGlyph";
  }
}